package test.aat.ejinr.test;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;

import test.aat.ejinr.chkphone01.HttpRequest;

/**
 * @date 2016年6月17日 下午6:16:55
 * @author 新歌<xingeking@163.com>
 * @email xingeking@163.com
 * @version v1.0
 * @function 功能是：
 * @info java spring
 * @update none
 */
public class T {

	/**
	 * @info
	 * @param
	 * @return
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub  京K27065
		String s1 = HttpRequest.sendGet("http://apidatatest.datatang.com/data/credit/queryNightTravelProCnt",
				"apikey=35f23263d922e464ac872b54e1d25f46&rettype=json&carlicense=%E8%B1%ABAP369Y&starttime=201501&endtime=201512");
		
		System.out.println(getS(s1, "nightTravelTimes"));
		
		String s2 = HttpRequest.sendGet("http://apidatatest.datatang.com/data/credit/queryOverSpeedCnt",
				"apikey=35f23263d922e464ac872b54e1d25f46&rettype=json&carlicense=粤YDD937&starttime=201401&endtime=201412");
		
		System.out.println(s2);
		
		String s3 = HttpRequest.sendGet("http://apidatatest.datatang.com/data/credit/queryLongtimeDrive",
				"apikey=35f23263d922e464ac872b54e1d25f46&rettype=json&carlicense=粤YDD937&starttime=201401&endtime=201412");
		
		System.out.println(getS(s3, "overspeedtimes"));
	}
	
	public static void writeS(String str, String encoding, String file) {
		char[] cuf = str.toCharArray();// 将指定的字串序列化为byte[]
		try {
			OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(file), encoding);
			out.write(cuf);
			out.flush();
			out.close();
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}
	
	
	public static String getS(String str,String f){
		if(str!=null&&str.contains(f));
		int i = str.indexOf(f)+f.length()+2;
		str = str.substring(i, i+4).trim();
		return str;
	}

}
